package Operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created by Salted fish
 * Description:
 * User: 24539
 * Date：2021-09-22
 * Time: 15:46
 */
public class DelOperation implements Opface{
    @Override
    public void work(BookList bookList) {
        System.out.println("删除图书 ");
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入删除图书的名字： ");
        String name = scanner.next();
        int size = bookList.getUsedSize();
        int mark = -1;
        for(int i = 0; i<size;i++) {
            Book book1 = bookList.getBook(i);
            if(book1.getName().equals(name)) {
                mark = i;
                break;
            }
        }
        if(mark != -1) {
            for (int a = mark; a < size -1; a++) {
                Book book = bookList.getBook(a+1);
                bookList.setBooks(a,book);
            }
            bookList.setUsedSize(size-1);
            System.out.println("删除成功");
            return;
        }
        System.out.println("删除失败");
    }
}
